﻿picShare.factory("Repository", function () {
    var that = this;

    var multiDictionary = (function () { //    :-)

        this.table = {};

        this.setItemToTable = function (key, val) {
            if (table.hasOwnProperty(key)) {
                table[key].push(val);
            }
            if (table[key] == undefined) {
                table[key] = [];
                table[key].push(val);
            }
        };

        this.getItemFromTable = function (key) {
            if (table.hasOwnProperty(key)) {
                return table[key];
            } else {
                return null;
            }
        };

        this.getAllItemsFromTable = function () {
            var objList = [];
            for (var key in table) {
                var obj = table[key];
                for (var prop in obj) {
                    if (obj.hasOwnProperty(prop)) {
                        objList.push(obj[prop]);
                    }
                }
            }

            return objList;
        };

        return {
            setItem: setItemToTable,
            getItem: getItemFromTable,
            getAll: getAllItemsFromTable,
            table: table
        };
    })();


    return {
        setItem: function (key, val) {
            return multiDictionary.setItem(key, val);
        },
        getItem: function (key) {
            return multiDictionary.getItem(key);
        },
        table:multiDictionary.table
    };
})